import { Injectable, OnModuleDestroy, OnModuleInit } from "@nestjs/common"

import {createClient,RedisClientType } from 'redis';
import { LongConnsService } from "./long.conns.service";

@Injectable()
export class RedisService implements OnModuleInit,OnModuleDestroy {
    redisClient : RedisClientType = null
    constructor(
        private gateWayService : LongConnsService
    ) {}

    redis(){
        return this.redisClient
    }

    async onModuleInit() {
        let redisClient :any = await createClient({
            url: 'redis://134.175.224.228:6379',
            password: 'b88888888',
            database: 8
          })
            .on('error', err => console.log('Redis Client Error', err))
            .on('ready', () => {

            })
            .connect();

        this.redisClient = redisClient
    }

    async onModuleDestroy() {
        await this.redisClient.disconnect()
    }
}